﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Engine
{
    public class DemonstrationalEngine
    {

        private Lattice lattice;

        private int xLenght;
        
        private int yLenght;
        
        /** <see cref="Engine.Lattices"/> */
        private int latticeType;

        public int LatticeType
        {
            get { return latticeType; }
            set 
            { 
                if((int)Lattices.Square == value)
                {
                    lattice = new Square();
                }
                else if ((int)Lattices.Triangular == value)
                {
                    lattice = new Triangular();
                }
                else
                {
                    throw new ArgumentException("unknow type of lattice.");
                }
                latticeType = value;
            }
        }

        public double PointIntegrityLevel
        {
            get
            {
                return (((double)lattice.WorkingPoints) / (lattice.WorkingPoints + lattice.CuttedPoints));
            }
        }

        public double BondIntegrityLevel
        {
            get
            {
                return (((double)lattice.WorkingBonds) / (lattice.WorkingBonds + lattice.CuttedBonds));
            }
        }

        public IList<Point> Points
        {
            get { return lattice.Points; }
        }

        public IList<Bond> Bonds
        {
            get { return lattice.Bonds; }
        }

        public int Xlenght 
        { 
            get { return xLenght + 2; }
        }
        public int Ylenght 
        { 
            get 
            { 
                return yLenght + 2; 
            }
        }


        public DemonstrationalEngine(int latticeType)
        {
            this.latticeType = latticeType;
            if ((int)Lattices.Square == latticeType)
            {
                lattice = new Square();
                xLenght = 10;
                yLenght = 10;
            }
            else if ((int)Lattices.Triangular == latticeType)
            {
                lattice = new Triangular();
                xLenght = 9;
                yLenght = 9;
            }
            else 
            { 
                throw new ArgumentException("unknown type of lattice");
            }
            //we will use only 2-dimensional lattice.
            lattice.X = xLenght;
            lattice.Y = yLenght;
        }

        public void CutBond()
        {
            lattice.CutBond();
        }

        public void CutPoint()
        {
            lattice.CutPoint();
        }

        public bool isConduct()
        {
            return lattice.IsConduct();
        }

    }
}
